from selenium import webdriver
import time
def login():
    driver = webdriver.Firefox()
    driver.get(r'http://127.0.0.1:8080/oa/')
    try:
        # 定位用户名文本框
        user_name_ele = driver.find_element('xpath',
                                                 '/html/body/div/div[5]/form/div/div[2]/table/tbody/tr[1]/td[2]/input')
        # 输入用户名
        user_name_ele.send_keys('admin')
        # 定位密码文本框
        password_ele = driver.find_element('xpath',
                                                '/html/body/div/div[5]/form/div/div[2]/table/tbody/tr[2]/td[2]/input')
        # 输入密码
        password_ele.send_keys('sys123456')
        # 定位登录按钮并点击
        driver.find_element('id', 'button_submit').click()
        return driver
    except Exception as e:
        print('登录失败！错误信息：',e)
